﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">
        $.fn.addItems = function(data) {
            return this.each(function() {
                var list = this;
                $.each(data, function(index, itemData) {
                    var option = new Option(itemData.Text); 

                    list.add(option);
                });
            });
        };
        $(function() {
            $('#btnClick').click(function() {
                $.getJSON("/Home/GetData", null, function(data) {
                    $("#itemsList").addItems(data);
                });
            });
        });
    </script>

    <h2>
        <%= Html.Encode(ViewData["Message"]) %></h2>
    <button id="btnClick" name="btnClick">
        Click Me</button>
    <br />
    <select id="itemsList" name="itemsList" size="6">
    </select>
</asp:Content>
